// 设置 select默认选中
function setSltDefaultVal(sltid, value) {
	var slt = document.getElementById(sltid) == null ? parent.document
			.getElementById(sltid) : document.getElementById(sltid);
	if(slt==null){
		return;
	}
	for (var i = 0; i < slt.length; i++) {
		if (slt[i].value == value){
			slt.selectedIndex = i;
			break;
		}
	}
}
//格式化表格
function initTable() {
	$(".innerStyle").css('display', '');
	$(".innerStyle font").css({
				"color" : "red",
				"font-size" : "12px"
			});
	$(".innerStyle th").css({
				"background-color" : "f1f1f1",
				color : "black"
			});
	$(".innerStyle tr td").not(':has(input)').not(':has(select)').css({
				"background-color" : "f0f8ff"
			})
	/*$(".innerStyle tr").not(':has(th)').mouseover(function() {
				$(this).addClass("over");
			}).mouseout(function() {
				$(this).removeClass("over");
			})*/
}
var lastIndex_lx = 0;
var curRecObj = null;
var resArr = new Array();
function initTblZBRY(){
	$('#tblZBRY').datagrid({
		url:"",
		striped : true,
		pageSize : 10,
		height : 310,
		nowrap : false,
		showPageList:false,
		columns : [[ {
					field : 'yjcz09020',
					title : '值班单位',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz09030',
					title : '值班人员',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz09110',
					title : '值班人员职务',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz09035',
					title : '移动电话',
					width : 100,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz09040',
					title : '性别',
					width : 35,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz09050',
					title : '办公电话',
					width : 100,
					align : 'center',
					editor : 'text'
				}/*,{
					field : 'yjcz09060',
					title : '办公传真',
					width : 75,
					align : 'center',
					editor : 'text'
				},*//*{
					field : 'yjcz09070',
					title : '家庭电话',
					width : 75,
					align : 'center',
					editor : 'text'
				},*//*{
					field : 'yjcz09080',
					title : '邮编',
					width : 40,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz09090',
					title : '通讯地址',
					width : 100,
					align : 'center',
					editor : 'text'
				}*//*,{
					field : 'yjcz09100',
					title : '电子邮箱',
					width : 60,
					align : 'center',
					editor : 'text'
				}*/,{
					field : 'oper',
					title : '操作',
					width : 120,
					align : 'center',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
						resArr.push(rec);
						var num = resArr.length-1;
						var resutsHTML = "";
						var pid = rec.yjcz09000;
						var resutsHTML = "<div style='align:center;'>"
								+ "<a name='showDetails' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showDetails(\""
								+ num
								+ "\",false)'>详情</a>"
								+ "<a name='addLink' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showDetails(\""
								+ num
								+ "\",true)'>修改</a>"
								+ "<a name='saveLink' style='padding:5px;cursor:pointer;text-decoration: underline;' "
								+ "onclick='deleteZBRY(\"" + pid + "\");'>删除</a>"
								+"</div>";
						return resutsHTML;
					}
				}]],
		pagination : true,
		rownumbers : true,
		singleSelect : true,
		/*toolbar : [{
			text : '添加',
			iconCls : 'icon-add',
			handler : function() {
				$('#tblZBRY').datagrid('cancelEdit', lastIndex_lx);
				$('#tblZBRY').datagrid('appendRow', {
							jdmc : '',
							oper : 0
						});
				
				var lastRowIndex = $('#tblZBRY')
						.datagrid('getRows').length
						- 1;
				$('#tblZBRY').datagrid('beginEdit', lastRowIndex);
				lastIndex_lx = lastRowIndex;
			}
		}, '-', {
			text : '回退',
			iconCls : 'icon-undo',
			handler : function() {
				$('#tblZBRY').datagrid('rejectChanges');
			}
		}],*/
		onClickRow : function(rowIndex) {
			//editZBRYDetails(rowIndex);
		},
		rownumbers : true,
		singleSelect : true
	});
}
function showDetails(initPid,isEdit){
	
	//$('#tblZBRY').datagrid('cancelEdit', lastIndex_lx);
	var curRecObj = resArr[initPid];
	
	$("#yjcz09000").attr("value",curRecObj.yjcz09000);
	$("#yjcz09010").attr("value",curRecObj.yjcz09010);
	$("#yjcz09020").attr("value",curRecObj.yjcz09020);
	$("#yjcz09030").attr("value",curRecObj.yjcz09030);
	$("#yjcz09035").attr("value",curRecObj.yjcz09035);
	$("#yjcz09040").attr("value",curRecObj.yjcz09040);
	$("#yjcz09050").attr("value",curRecObj.yjcz09050);
	$("#yjcz09060").attr("value",curRecObj.yjcz09060);
	//$("#yjcz09070").attr("value",curRecObj.yjcz09070).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz09080").attr("value",curRecObj.yjcz09080);
	$("#yjcz09090").attr("value",curRecObj.yjcz09090);
	$("#yjcz09100").attr("value",curRecObj.yjcz09100);
	$("#yjcz09110").attr("value",curRecObj.yjcz09110);
	$("#yjcz09120").attr("value",curRecObj.yjcz09120);
	if(!isEdit){
		$("#detailsDialog_zbry input[type=text]").attr("readOnly","isReadOnly").attr("disabled","isDisabled");
		$("#submitBtn").css("display","none");
		$("#resetBtn").css("display","none");
	}else{
		$("#detailsDialog_zbry input[type=text]").removeAttr("readOnly").removeAttr("disabled");
		$("#submitBtn").css("display","");
		$("#resetBtn").css("display","");
	}
	$("#detailsDialog_zbry").dialog('open');
	
}
function deleteZBRY(initPid){
	var bln = confirm('是否删除该值班人员信息');
	if (!bln) {
		return;
	}
	var url = "deleteZBRYById.shtml";
	var data = {
		"id" : initPid
	}
	$.post(url, data, delZBRYResult);
}
function delZBRYResult(res){
	if(res){
		alert("删除成功");
		$('#tblZBRY').datagrid('reload');
	}else
		alert("删除失败");
	$("#detailsDialog").dialog('close');
}
function updateZBRY(){
	url = "updateZBRYById.shtml";
	var dataObj = {
		"yjcz09000":$("#yjcz09000").val(),
		"yjcz09010":$("#yjcz09010").val(),
		"yjcz09020":$("#yjcz09020").val(),
		"yjcz09030":$("#yjcz09030").val(),
		"yjcz09035":$("#yjcz09035").val(),
		"yjcz09040":$("#yjcz09040").val(),
		"yjcz09050":$("#yjcz09050").val(),
		"yjcz09060":$("#yjcz09060").val(),
		//"yjcz09070":$("#yjcz09070").val(),
		"yjcz09080":$("#yjcz09080").val(),
		"yjcz09090":$("#yjcz09090").val(),
		"yjcz09100":$("#yjcz09100").val(),
		"yjcz09110":$("#yjcz09110").val(),
		"yjcz09120":$("#yjcz09120").val()
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"yjcz09":data}, updateResult);
}
function updateResult(res){
	if(res.jsonResult){
		alert("更新成功");
		$('#tblZBRY').datagrid('reload');
	}else
		alert("更新失败");
	$("#detailsDialog").dialog('close');
}
function resetTbl(){
	$(".innerStyle input").not("button").attr("value","");
}
function addNewZBRY(){
	
	url = "updateZBRYById.shtml";
	if($("#addyjcz09030").val()==""){
		alert("值班人员姓名不能为空");
		return;
	}
	var loginName = $("#addLoginName").val();
	var userPass = $("#addUserPass").val();
	var department = $("#addUserDepartment").val();
	var role = $("#addUserRole").val();
	var userName = $("#addyjcz09030").val();
	if(loginName==""&&userPass==""&&$("#addUserPassSub").val()==""){
		alert("请填写用户必要信息");
		return;
	}else{
		if($("#addUserPassSub").val()!=userPass){
			alert("密码和确认密码必须一致");
			return;
		}
	}
	var region =$("#sheng_zbry").val();
	if($("#addxian_zbry").val()!="-1"){
		region = $("#addxian_zbry").val();
	}else if($("#addshi_zbry").val()!="-1"){
		region = $("#addshi_zbry").val();
	}
	var dataObj = {
		"yjcz09000":$("#addyjcz09000").val(),
		"yjcz09010":region,
		"yjcz09020":$("#addyjcz09020").val(),
		"yjcz09030":$("#addyjcz09030").val(),
		"yjcz09035":$("#addyjcz09035").val(),
		"yjcz09040":$("#addyjcz09040").val(),
		"yjcz09050":$("#addyjcz09050").val(),
		"yjcz09060":$("#addyjcz09060").val(),
		//"yjcz09070":$("#addyjcz09070").val(),
		"yjcz09080":$("#addyjcz09080").val(),
		"yjcz09090":$("#addyjcz09090").val(),
		"yjcz09100":$("#addyjcz09100").val(),
		"yjcz09110":$("#addyjcz09110").val(),
		"yjcz09120":$("#addyjcz09120").val()
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"yjcz09":data,
		loginName:loginName,
		userPass:userPass,
		department:department,
		role:role,
		userName:userName,
		region:region}, updateResult);
}
function setAreaCode(){
	var area =zhen;//镇
	if(area=="")
		area = xian;//县
	if(area=="")
		area = shi;//市
	if(area=="")
		area = shen;//省
	if(area==""){
		alert("请选择行政区域");
		return false;
	}
	return area;
}
function queryZBRYByKeyword(){
	resArr = new Array();
	var condition = setAreaCode();
	var qName = $("#qName_zbry").val();
	var url = "queryZBRYList.shtml";
	var data = {
		"condition":condition,
		"qName":qName
	}
	var val = $("#region").val();
	if(val=="")
		//initTblZBRY();
	$('#tblZBRY').datagrid({
				url : url,
				queryParams : data,
				onLoadSuccess : function(res) {
					//$("#region").attr("value",res.selects[0]);
				},
				onLoadError : function(res) {
					alert("查询失败!");
				}
			});
}
function queryZBByKeyword(){
	//debugger;
	resArr = new Array();
	var condition = setAreaCode();
	var qName = $("#qName").val();
	var startTime = $("#startTime").val();
	var endTime = $("#endTime").val();
	var url = "queryZBGLList.shtml";
	var data = {
		"condition":condition,
		"qName":qName,
		"sTime":startTime,
		"eTime": endTime
	}
	$('#tblZBGL').datagrid({
				url : url,
				queryParams : data,
				onLoadError : function(res) {
					alert("查询失败!");
				}
			});
}

function zeroize (value, length) {  
	if (!length) {  
		length = 2;  
	}  
	value = new String(value);  
	for (var i = 0, zeros = ''; i < (length - value.length); i++) {  
		zeros += '0';  
	}  
	return zeros + value;  
}; 
function getDateFromTime(time){
	var date = new Date(time);
	var year = date.getFullYear();
	var month = zeroize(date.getMonth() + 1,2);
	var day = zeroize(date.getDate(),2);
	var h = zeroize(date.getHours() % 24,2) ;
	var m =  zeroize(date.getMinutes(),2);
	return year+"-"+month +"-"+day+" "+h+":"+m+":00";
}
function initTblZBGL(){
	$('#tblZBGL').datagrid({
		url:"",
		striped : true,
		pageSize : 10,
		height : 295,
		nowrap : false,
		columns : [[ {
					field : 'yjcz10020',
					title : '值班单位',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10050',
					title : '值班人员',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10030',
					title : '值班日期(起)',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10040',
					title : '值班日期(止)',
					width : 150,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10060',
					title : '带班领导',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10070',
					title : '主管领导',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10080',
					title : '分管领导',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz10090',
					title : '应急值班电话1',
					width : 100,
					align : 'center',
					editor : 'text'
				},{
					field : 'oper',
					title : '操作',
					width : 150,
					align : 'center',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
						resArr.push(rec);
						var num = resArr.length-1;
						var resutsHTML = "";
						var pid = rec.yjcz10000;
						var resutsHTML = "<div style='align:center;'>"
								+ "<a name='showDetails' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showZBGLDetails(\""
								+ num
								+ "\",false)'>详情</a>"
								+ "<a name='addLink' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showZBGLDetails(\""
								+ num
								+ "\",true)'>修改</a>"
								+ "<a name='saveLink' style='padding:5px;cursor:pointer;text-decoration: underline;' "
								+ "onclick='deleteZBGL(\"" + pid + "\");'>删除</a>"
								+"</div>";
						return resutsHTML;
					}
				}]],
		pagination : true,
		rownumbers : true,
		singleSelect : true,
		rownumbers : true,
		singleSelect : true
	});
}
function updateZBGL(){
	url = "../updateZBGLById.shtml";
	var isDB =  $("input[type=radio][checked]").val();
	var dataObj = {
		"yjcz10000":$("#yjcz10000").val(),
		"yjcz10005":$("#yjcz10005").val(),
		"yjcz10010":isDB,
		"yjcz10020":$("#yjcz10020").val(),
		"yjcz10030":$("#yjcz10030").val(),
		"yjcz10040":$("#yjcz10040").val(),
		"yjcz10050":$("#yjcz10050").val(),
		"yjcz10060":$("#yjcz10060").val(),
		"yjcz10070":$("#yjcz10070").val(),
		"yjcz10080":$("#yjcz10080").val(),
		"yjcz10090":$("#yjcz10090").val(),
		"yjcz10100":$("#yjcz10100").val(),
		"yjcz10110":$("#yjcz10110").val(),
		"yjcz10120":$("#yjcz10120").val(),
		"yjcz10130":$("#yjcz10130").val(),
		"yjcz10140":$("#yjcz10140").val(),
		"yjcz10150":$("#yjcz10150").val()
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"yjcz10":data,"sTime":$("#yjcz10030").val(),eTime:$("#yjcz10040").val()}, updateZBFLResult);
}
function updateZBFLResult(res){
	if(res){
		alert("更新成功");
		$('#tblZBGL').datagrid('reload');
	}else{
		alert("更新失败");
	}
	$("#detailsDialog").dialog('close');
}
function deleteZBGL(pid){
	var bln = confirm('是否删除该值班记录信息');
	if (!bln) {
		return;
	}
	var url = "../deleteZBGLById.shtml";
	var data = {
		"id" : pid
	}
	$.post(url, data, delZBGLResult);
}
function delZBGLResult(res){
	if(res){
		alert("删除成功");
		$('#tblZBGL').datagrid('reload');
	}else
		alert("删除失败");
	$("#detailsDialog").dialog('close');
}
function showZBGLDetails(initPid,isEdit){
	var curRecObj = resArr[initPid];
	var isReadOnly = "readOnly";
	var isDisabled = "disabled";
	var isDisPlay = "none";
	if(isEdit){
		isReadOnly = "";
		isDisabled = "";
		isDisPlay = "";
	}
	var sTime = curRecObj.yjcz10030==null?"":curRecObj.yjcz10030;
	var eTime = curRecObj.yjcz10040==null?"":curRecObj.yjcz10040;
	sTime=sTime.replace("T"," ");
	eTime=eTime.replace("T"," ");
	$("#yjcz10000").attr("value",curRecObj.yjcz10000);
	$("#yjcz10005").attr("value",curRecObj.yjcz10005);
	$("input[type=radio][name=yjcz10010][value="+curRecObj.yjcz10010+"]").attr("checked","checked");
	//$("#yjcz10010").attr("value",curRecObj.yjcz10010).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10020").attr("value",curRecObj.yjcz10020).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10030").attr("value",sTime).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10040").attr("value",eTime).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10050").attr("value",curRecObj.yjcz10050).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10060").attr("value",curRecObj.yjcz10060).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10070").attr("value",curRecObj.yjcz10070).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10080").attr("value",curRecObj.yjcz10080).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10090").attr("value",curRecObj.yjcz10090).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10100").attr("value",curRecObj.yjcz10100).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10110").attr("value",curRecObj.yjcz10110).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10120").attr("value",curRecObj.yjcz10120).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10130").attr("value",curRecObj.yjcz10130).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#yjcz10140").attr("value",curRecObj.yjcz10140).attr("readOnly","readOnly").attr("disabled","disabled");
	$("#yjcz10150").attr("value",curRecObj.yjcz10150).attr("readOnly",isReadOnly).attr("disabled",isDisabled);
	$("#submitBtn").css("display",isDisPlay);
	$("#resetBtn").css("display",isDisPlay);
	$("#detailsDialog").dialog('open');
}
function setSelValue(selectid,text){
	var temp= document.getElementById(selectid);
	temp.innerHTML="";
	temp.options[0]= new Option("请选择人员",-1);
	var v = eval(text);
	for(var i=1;i<v.length;i++){
		var obj = v[i-1];
		temp.options[i]=new Option(obj[0],obj[1]);
	}
}
var sltPersonArr;
function loadZBRYSlt(parentid,region){
	sltPersonArr = new Array();
	var reg = region;
	if(parentid=='addshi_zbgl'&&region=="-1"){
		reg = $("#addshi_zbgl").val();
	}
	var url='../findZBRYNameList.shtml?condition='+reg;
	$.post(url, '', getZBRYNameListRes);
}

function getZBRYNameListRes(res){
	var resultArray = res.rows;
	setSelValue('addyjcz10050',resultArray);
	setSelValue('addyjcz10060',resultArray);
	//setSelValue('addyjcz10070',resultArray);
	//setSelValue('addyjcz10080',resultArray);
	sltPersonArr = eval(resultArray);
}
function getUnitByPerson(personId){
	for(var i=0;i<sltPersonArr.length;i++){
		var obj = sltPersonArr[i];
		if(obj[1]==personId){
			$("#addyjcz10020").attr("value",obj[2]);
			break;
		}
			
	}
}
function addNewZBGL(){
	var url = "../updateZBGLById.shtml";
	if($("#addyjcz10050").val()=="-1"){
		alert("值班人员姓名不能为空");
		return;
	}
	if($("#addyjcz10060").val()=="-1"){
		alert("带班领导姓名不能为空");
		return;
	}
	if($("#addyjcz10070").val()=="-1"){
		alert("主管领导姓名不能为空");
		return;
	}
	if($("#addyjcz10080").val()=="-1"){
		alert("分管领导姓名不能为空");
		return;
	}
	var region =$("#sheng").val();
	if($("#addxian_zbgl").val()!="-1"){
		region = $("#addxian_zbgl").val();
	}else if($("#addshi_zbgl").val()!="-1"){
		region = $("#addshi_zbgl").val();
	}
	var isDB =  $("input[type=radio][name=addyjcz10010][checked]").val();
	var dataObj = {
		"yjcz10000":$("#addyjcz10000").val(),
		"yjcz10005":region,
		"yjcz10010":isDB,
		"yjcz10020":$("#addyjcz10020").val(),
		"yjcz10030":$("#addyjcz10030").val(),
		"yjcz10040":$("#addyjcz10040").val(),
		"yjcz10050":$("#addyjcz10050").find("option:selected").text(),
		"yjcz10060":$("#addyjcz10060").find("option:selected").text(),
		"yjcz10070":$("#addyjcz10070").find("option:selected").text(),
		"yjcz10080":$("#addyjcz10080").find("option:selected").text(),
		"yjcz10090":$("#addyjcz10090").val(),
		"yjcz10100":$("#addyjcz10100").val(),
		"yjcz10110":$("#addyjcz10110").val(),
		"yjcz10120":$("#addyjcz10120").val(),
		"yjcz10130":$("#addyjcz10130").val(),
		"yjcz10140":$("#addyjcz10140").val(),
		"yjcz10150":$("#addyjcz10150").val()
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"yjcz10":data}, updateZBFLResult);
}
//获取当前登录人的未填写的登录日志
function getCurrentDutyLog(useName){
	var logIsUpdate = $.post(url,data, "");
	
	$("#logManageDiv").html("");
	var url = "../findZBGLLog.shtml";
	var data ={
		"userName":useName
	}
	$.post(url,data, cbGetCurrentDutyLog);
}
function cbGetCurrentDutyLog(res){
	var logIsUpdate = res.jsonResult
	if(logIsUpdate==0){
		alert('您没有权限值班')
		return;
	}else if(logIsUpdate==1){
		alert('您的值班记录已经填写完毕，请在值班记录查询里更新')
		$('#tabsdiv').tabs('select','值班记录查询');
		return;
	}
	
	var objList = eval(res.rows);
	
	var obj = null;
	var html = "<table class='innerStyle'>";
	if(objList.length>0){
		obj = objList[0];
		var bln = confirm('当前排班表存在您的排班记录，是否开始值班？');
		if (!bln) {
			return;
		}
		//$("#logYjcz10000").attr("value",obj.yjcz10000);
		//var sTime = getDateFromTime(obj.yjcz10030.time);
		//var eTime = getDateFromTime(obj.yjcz10040.time);
		var sTime = obj.yjcz10030.replace("T"," ");
		var eTime = obj.yjcz10040.replace("T"," ");
		//var isDB = obj.yjcz10010==0?"否":"是";
		//html +="<tr><td>值班单位</td><td><input type='text' value='"+obj.yjcz10020+"'/></td>" 
		html +="<td>值班人员</td><td><input type='text' id='yjcz04020' value='"+obj.yjcz10050+"'/></td></tr>"
		html +="<tr><td>值班日期（起）</td><td><input type='text' id='yjcz04093' value='"+sTime+"'/></td>" 
		html +="<td>值班日期（止）</td><td><input type='text' id='yjcz04094' value='"+eTime+"'/></td></tr>" 
		//html +="<tr><td>是否代班</td><td><input type='text' value='"+isDB+"'></td>" 
		html +="<td>带班领导</td><td><input type='text' id='yjcz04030' value='"+obj.yjcz10060+"'/></td></tr>" 
		//html +="<tr><td>主管领导</td><td><input type='text' value='"+obj.yjcz10070+"'/></td>" 
		//html +="<td>分管领导</td><td><input type='text' value='"+obj.yjcz10080+"'/></td></tr>" 
		//html +="<tr><td>应急值班电话1</td><td><input type='text' value='"+obj.yjcz10090+"'/></td>" 
		//html +="<td>应急值班电话2</td><td><input type='text' value='"+obj.yjcz10100+"'></td></tr>" 
		//html +="<tr><td>应急值班电话3</td><td><input type='text' value='"+obj.yjcz10110+"'/></td>" 
		//html +="<td>值班坐席编号</td><td><input type='text' value='"+obj.yjcz10120+"'/></td></tr>" 
		// +="<tr><td>应急值班传真</td><td><input type='text' value='"+obj.yjcz10130+"'/></td>" 
		//html +="<td>备注</td><td><input type='text' value='"+obj.yjcz10150+"'/></td></tr>" 
		html +="<tr><td colspan='1'>值班日志</td>" 
		html +="<td colspan='3'><textarea style='width:100%' id='yjcz04092' >"+obj.yjcz10140+"</textarea></td></tr>"
		html +="<tr><td colspan='4' align='center'><input  type='button' value='保存' class='btn_2z'	onclick='updateLog()' /></td>" +
				"</tr>";
		html +="</table>";
		$("#logManageDiv").html(html);
	}else{
		var bln = confirm('当前排班表不存在您的排班记录，是否开始值班？');
		if (!bln) {
			return;
		}
		var uName = top.$("#userDiv").html();
		html +="<tr><td>值班人员</td><td><input type='text' id='yjcz04020' disabled='disabled' readOnly='readOnly' value='"+uName+"'/></td></tr>"
		html +="<tr><td>值班日期（起）</td><td><input id=yjcz04093  class='Wdate' type='text' onfocus=\"WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})\"/></td>" 
		html +="<td>值班日期（止）</td><td><input id=yjcz04094  class='Wdate' type='text' onfocus=\"WdatePicker({startDate:'%y-%M-01 00:00:00',dateFmt:'yyyy-MM-dd HH:mm:ss',alwaysUseStartDate:true})\"/></td></tr>" 
		html +="<td>带班领导</td><td><select id='yjcz04030'  > </select></td></tr>" 
		html +="<tr><td colspan='1'>值班日志</td>" 
		html +="<td colspan='3'><textarea style='width:100%' id='yjcz04092' >"+''+"</textarea></td></tr>"
		html +="<tr><td colspan='4' align='center'><input  type='button' value='保存' class='btn_2z'	onclick='updateLog()' /></td>" +
				"</tr>";
		html +="</table>";
		$("#logManageDiv").html(html);
		//加载人员列表
		var url='../findZBRYNameList.shtml?condition=420000';
		$.post(url, '', initDBLD);
	}
	
	$("#logManageDiv input[type=text]").attr("disabled","");
	$('#tabsdiv').tabs('select','日志编辑');
}
function initDBLD(res){
	var resultArray = res.rows;
	setSelValue('yjcz04030',resultArray);
}
function updateLog(){
	var url ="../updateZBGLLog.shtml";
	var dataObj ={
		"yjcz04000":"000000",
		"yjcz04010":"2012-1-1 00:00:00",
		"yjcz04020":$("#yjcz04020").val(),
		"yjcz04093":$("#yjcz04093").val(),
		"yjcz04094":$("#yjcz04094").val(),
		"yjcz04030":$("#yjcz04030").val(),
		"yjcz04092":$("#yjcz04092").val()
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"yjcz04":data}, cbUpdateLog);
	
}
function cbUpdateLog(response){
	var res = response.jsonResult.split(",");
	if(res[0]){
		alert("更新成功");
		$('#tblZBJL').datagrid('reload');
		$("#detailsDialog_zbjl").dialog("close");
	}else
		alert("更新失败");
}
function exportXLS(type){
	/*var startTime = $("#startTime").val();
	var endTime = $("#endTime").val();*/
	debugger;
	var date = $('#yjzb_ForCalendar').fullCalendar('getDate');
	var year = date.getFullYear();
	var month = date.getMonth()+1;
	var startTime = year+"-"+month+"-"+1;
	var endTime = year+"-"+month+"-"+getMonthDays(month);
	var url = "../exportJasper"+type+".shtml?";
	
	var dd = window.open(url + "&sTime=" + startTime + "&eTime="
					+ endTime , "_self");
}

function showDialogAddZbry(){
	$("#Dialog_addzbry").dialog("open");
}

function addPbjl(){
	$("#Dialog_addPbjl").dialog("open");
}


function initTblZBJL(role){
	$('#tblZBJL').datagrid({
		url:"",
		striped : true,
		pageSize : 10,
		height : 295,
		nowrap : false,
		columns : [[ {
					field : 'yjcz04020',
					title : '值班人员',
					width : 60,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz04093',
					title : '值班日期(起)',
					width : 170,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz04094',
					title : '值班日期(止)',
					width : 170,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz04092',
					title : '值班日志',
					width : 100,
					align : 'center',
					editor : 'text'
				},{
					field : 'yjcz04095',
					title : '应急处置',
					width : 100,
					align : 'center',
					editor : 'text'
				},{
					field : 'oper',
					title : '操作',
					width : 150,
					align : 'center',
					formatter : function(value, rec, rowIndex) {// value id rec
						// 该对象
						//curRecObj = rec;
						resArr.push(rec);
						var num = resArr.length-1;
						var resutsHTML = "";
						var pid = rec.id;
						var resutsHTML = "<div style='align:center;'>"
								+ "<a name='showDetails' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showZBJLDetails(\""
								+ num
								+ "\",false)'>详情</a>"
								+ "<a name='addLink' style='padding:5px;cursor:pointer;text-decoration: underline;' onclick='showZBJLDetails(\""
								+ num
								+ "\",true,\""+role+"\")'>修改</a>"
								+ "<a name='saveLink' style='padding:5px;cursor:pointer;text-decoration: underline;' "
								+ "onclick='deleteZBJL(\"" + pid + "\");'>删除</a>"
								+"</div>";
						return resutsHTML;
					}
				}]],
		pagination : true,
		rownumbers : true,
		singleSelect : true,
		rownumbers : true,
		singleSelect : true
	});
}
function queryBtn_zbjl(){
	resArr = new Array();
	var condition = setAreaCode();
	var qName = $("#qName_zbjl").val();
	var startTime = $("#startTime_zbjl").val();
	var endTime = $("#endTime_zbjl").val();
	var url = "queryZBJLList.shtml";
	var data = {
		"condition":condition,
		"qName":qName,
		"sTime":startTime,
		"eTime": endTime
	}
	$('#tblZBJL').datagrid({
				url : url,
				queryParams : data,
				onLoadError : function(res) {
					alert("查询失败!");
				}
			});
}
function exportBtn_zbjl(){
	
	var startTime = $("#startTime_zbjl").val();
	var endTime = $("#endTime_zbjl").val();
	var url = "../exportJasperZBJL.shtml?";
	
	var dd = window.open(url + "&sTime=" + startTime + "&eTime="
					+ endTime , "_self");
}
///modify by cuiyi  增加第三个参数  role  用来判断是否是管理员角色。与后台值班记录维护zbjlwh.jsp有关
function showZBJLDetails(initPid,isEdit,role){
	var curRecObj = resArr[initPid];
	/*var isReadOnly = "readOnly";
	var isDisabled = "disabled";
	var isDisPlay = "none";
	if(isEdit){
		isReadOnly = "";
		isDisabled = "";
		isDisPlay = "";
	}*/
	var sTime = curRecObj.yjcz04093==null?"":curRecObj.yjcz04093;
	var eTime = curRecObj.yjcz04094==null?"":curRecObj.yjcz04094;
	sTime=sTime.replace("T"," ");
	eTime=eTime.replace("T"," ");
	if(isEdit){
		var curDate = new Date();
		var startYear = sTime.split(" ")[0].split("-")[0];
		var startMonth = sTime.split(" ")[0].split("-")[1];
		var startDay = sTime.split(" ")[0].split("-")[2];
		var startHour = sTime.split(" ")[1].split(":")[0];
		var startMinute = sTime.split(" ")[1].split(":")[1];
		var startSecond = sTime.split(" ")[1].split(":")[2];
		var startDate = new Date(startYear,startMonth-1,startDay,startHour,startMinute,startSecond);
		var endYear = eTime.split(" ")[0].split("-")[0];
		var endMonth = eTime.split(" ")[0].split("-")[1];
		var endDay = eTime.split(" ")[0].split("-")[2];
		var endHour = eTime.split(" ")[1].split(":")[0];
		var endMinute = eTime.split(" ")[1].split(":")[1];
		var endSecond = eTime.split(" ")[1].split(":")[2];
		var endDate = new Date(endYear,endMonth-1,endDay,endHour,endMinute,endSecond);
		if((!(curDate>startDate&&curDate<endDate))&&role!="管理员"){
			alert("您不能修改记录!");
			return;
		}
	}
	$("#yjcz04id").attr("value",curRecObj.id);
	$("#yjcz04000").attr("value",curRecObj.yjcz04000);
	$("#yjcz04020").attr("value",curRecObj.yjcz04020);
	$("#yjcz04093").attr("value",sTime);
	$("#yjcz04094").attr("value",eTime);
	$("#yjcz04092").attr("value",curRecObj.yjcz04092);
	$("#yjcz04095").attr("value",curRecObj.yjcz04095);
	$(".leibie")[curRecObj.yjcz04005].checked = true;
	if(!isEdit){
		$("#detailsDialog_zbjl input[type=text]").attr("readOnly","isReadOnly").attr("disabled","isDisabled");
		$(".leibie").attr("readOnly","isReadOnly").attr("disabled","isDisabled");
		$("#submitBtn_zbjl").css("display","none");
		$("#resetBtn_zbjl").css("display","none");
	}else{
		$("#detailsDialog_zbjl input[type=text]").removeAttr("readOnly").removeAttr("disabled");
		$(".leibie").removeAttr("readOnly").removeAttr("disabled");
		$("#submitBtn_zbjl").css("display","");
		$("#resetBtn_zbjl").css("display","");
	}
	$("#detailsDialog_zbjl").dialog('open');
}

function updateZBJL(){
	var url ="updateZBGLLog.shtml";
	var dataObj ={
		"id":$("#yjcz04id").val(),
		"yjcz04000":$("#yjcz04000").val(),
		"yjcz04020":$("#yjcz04020").val(),
		"yjcz04093":$("#yjcz04093").val(),
		"yjcz04094":$("#yjcz04094").val(),
		"yjcz04030":$("#yjcz04030").val(),
		"yjcz04092":$("#yjcz04092").val(),
		"yjcz04095":$("#yjcz04095").val(),
		"yjcz04005":$("input:radio[name='leibie']:checked").val()
	}
	var data = JSON.stringify(dataObj);
	//alert(data);
	$.post(url,{"yjcz04":data}, cbUpdateLog);
	
}
function deleteZBJL(initPid){
	var bln = confirm('是否删除该条值班信息');
	if (!bln) {
		return;
	}
	var url = "../deleteZBJLById.shtml";
	var data = {
		"id" : initPid
	}
	$.post(url, data, delZBJLResult);
}
function delZBJLResult(res){
	if(res){
		alert("删除成功");
		$('#tblZBJL').datagrid('reload');
	}else
		alert("删除失败");
	$("#detailsDialog_zbjl").dialog('close');
}


//对于行政区划的处理函数,wangshaobo 于20120811//////////////////////////
function handlerAreaFunc(sheng,shi,xian){
	var areaCode = "";
	if(shi==""){
		areaCode = sheng.substring(0,2);
	}else if(xian==""){
		areaCode = shi.substring(0,4);
	}else{
		areaCode = xian;
	}
	return areaCode;
}

//对于地质灾害统一编码的处理函数,wangshaobo 于20120811
function handlerZhCodeFunc(areaCode,zhlx){
	var zhCode = "";
	if(zhlx){
		if(areaCode.length==2){
			zhCode = areaCode +"____"+zhlx+"____";
		}else if(areaCode.length==4){
			zhCode = areaCode +"__"+zhlx+"____";
		}else if(areaCode.length==6){
			zhCode = areaCode +zhlx+"____";
		}
	}else{
		if(areaCode.length==2){
			zhCode = areaCode +"__________";
		}else if(areaCode.length==4){
			zhCode = areaCode +"________";
		}else if(areaCode.length==6){
			zhCode = areaCode +"______";
		}
	}
	return zhCode;
}


//////////////////////////王少波为了应急值班的排班表所做的处理//////////////////////////////
function initFullCalendarForYJPB(){
	var url = "queryPaibanPlanListByMonth.shtml";
	$.post(url,{xzqCode:top.$("#lyCode").val()},function(res){
		res = eval(res);
		var eventSource = [];
		for(var i = 0;i<res.length;i++){
			var titleStr = "";
			var resObj = res[i];
			if(res[i].yjcz10030.hours==8){//表示是上午
				titleStr = "上午:";
			}
			if(res[i].yjcz10030.hours==12){//表示是下午
				titleStr = "下午:";
			}
			if(res[i].yjcz10030.hours==17){//表示是夜晚
				titleStr = "夜晚:";
			}
			var startYear = res[i].yjcz10030.year +1900;
			var startMonth = res[i].yjcz10030.month;
			var startDay = res[i].yjcz10030.date;
			var endYear = res[i].yjcz10040.year +1900;
			var endMonth = res[i].yjcz10040.month;
			var endDay = res[i].yjcz10040.date;
			var event = {title:titleStr+res[i].yjcz10050,
					start:new Date(startYear,startMonth,startDay),
					end:new Date(startYear,startMonth,startDay),
					logicStart:new Date(startYear,startMonth,startDay,res[i].yjcz10030.hours,res[i].yjcz10030.minutes),
					logicEnd:new Date(endYear,endMonth,endDay,res[i].yjcz10040.hours,res[i].yjcz10040.minutes),
					name:res[i].yjcz10050,
					logicId:res[i].yjcz10000
			};
			eventSource.push(event);
		}
		$("#yjpb_ForCalendar").fullCalendar({
			header: {
			right: 'prev,next today',
			left: 'title',
			},
			editable: false,
			disableDragging:false,
			firstDay:1,
			events:eventSource,
		});
	});
}



function forZhibanClickFunc(name){
	var url = "isThisOneDuty.shtml";
	$.post(url,{name:name},function(res){
		if(res=="true"){//表示是值班人员，那么记录填写的框肯定已经存在了，那么将其还原或者说不动
			alert("您已经是值班人员！");
		}else if(res=="false"){//表示是非值班人员，提示是否进行代班
			if(confirm("系统检测到您不是值班人员，是否进行代班?")){
				//修改数据库中的数据，将代班人员改成值班人员
				var url = "changePaibanPlanCaseDaiban.shtml";
				$.post(url,{name:name},function(res){
					if(res=="true"){
						top.loadZbjlDlg(name);
					}
				});
			}else{
				return ;
			}
		}else if(res =="cannot"){//表示这个人不是排班人员，同时也有人开始进行了值班，他什么都不能干
			alert("已经有人开始值班了，您不能进行代班!");
		}else if(res=="noplan"){
			alert("此时间内无排班计划!");
		}
	});
}

///////////////////////////王少波对应急值班里值班表查看的处理////////////
function initFullCalendarForYJZB(){
	var url = "queryZhibanPlanListByMonth.shtml";
	$.post(url,null,function(res){
		res = eval(res);
		var eventSource = [];
		for(var i = 0;i<res.length;i++){
			var titleStr = "";
			var resObj = res[i];
			if(res[i].yjcz14030.hours==8){//表示是上午
				titleStr = "上午:";
			}
			if(res[i].yjcz14030.hours==12){//表示是下午
				titleStr = "下午:";
			}
			if(res[i].yjcz14030.hours==17){//表示是夜晚
				titleStr = "夜晚:";
			}
			var startYear = res[i].yjcz14030.year +1900;
			var startMonth = res[i].yjcz14030.month;
			var startDay = res[i].yjcz14030.date;
			var endYear = res[i].yjcz14040.year +1900;
			var endMonth = res[i].yjcz14040.month;
			var endDay = res[i].yjcz14040.date;
			var event = {title:titleStr+res[i].yjcz14050,
					start:new Date(startYear,startMonth,startDay),
					end:new Date(startYear,startMonth,startDay),
					logicStart:new Date(startYear,startMonth,startDay,res[i].yjcz14030.hours,res[i].yjcz14030.minutes),
					logicEnd:new Date(endYear,endMonth,endDay,res[i].yjcz14040.hours,res[i].yjcz14040.minutes),
					name:res[i].yjcz14050
			};
			eventSource.push(event);
		}
		$("#yjzb_ForCalendar").fullCalendar({
			header: {
			right: 'prev,next today',
			left: 'title',
			},
			editable: false,
			disableDragging:false,
			firstDay:1,
			events:eventSource,
		});
	})
}

////////////////////王少波对值班统计所做的处理///////////////
function intTblZBTJ(){
	//对年份下拉表的值进行添加
	createOptionForYearSelect();
	var year = new Date().getFullYear();
	var month = new Date().getMonth();
	$("#chooseYearSelect").val(year);
	$("#chooseMonthSelect").val(month+1);
	$('#tblZBTJ').datagrid({
		url:"",
		striped : true,
		pageSize : 10,
		height : 295,
		nowrap : false,
		columns : [[ {
					field : 'name',
					title : '值班人员',
					width : 385,
					align : 'center',
					editor : 'text'
				},{
					field : 'count',
					title : '值班次数',
					width : 385,
					align : 'center',
					editor : 'text'
				}
				]],
		pagination : true,
		rownumbers : true,
		singleSelect : true,
		rownumbers : true,
		singleSelect : true
	});
	$("#tjBtn_zb").click(tjBtnClickFunc);
}

//统计按钮的点击事件
function tjBtnClickFunc(){
	$("#charBtn_zb").hide();
	$('#zbtj_charDlg').dialog("close");
	var year = $("#chooseYearSelect").val();
	var month = $("#chooseMonthSelect").val();
	if(year==""){
		alert("请填写年份!");
		return;
	}
	if(month==""){
		alert("请填写月份!");
		return;
	}
	var url = "queryZBTJList.shtml";
	var data = {
		"year":year,
		"month":month
	}
	$('#tblZBTJ').datagrid({
				url : url,
				queryParams : data,
				onLoadError : function(res) {
					alert("查询失败!");
				},
				onLoadSuccess : function(res) {
					//整理数据源
					handleZBTJDateSource(res);
				}
	
			});
}

//组织统计图的数据源
function handleZBTJDateSource(res){
	var chartXML = "<chart palette='2' caption='值班统计图' xAxisName='值班人员' yAxisName='值班次数' showValues='0' decimals='0' formatNumberScale='0' useRoundEdges='1'>";
	for(var i = 0;i<res.rows.length;i++){
		chartXML = chartXML + "<set label='"+res.rows[i].name+"' value='"+res.rows[i].count+"' />";
	}
	chartXML = chartXML +"</chart>";
	//整理完毕，按钮出现，点击事件注册，
	$("#charBtn_zb").show();
	$("#charBtn_zb").click(function(){
		showCharForZBTJ(chartXML);
	});
}

//值班统计统计图
function showCharForZBTJ(chartXML){
	var chart = new FusionCharts("../../lib/fusionChart/Column2D.swf", "ChartId", "400", "300", "0", "0");
	chart.setDataXML(chartXML);		   
	chart.render("zbtj_charDiv");
	$('#zbtj_charDlg').dialog("open");
}


//为年的下拉列表创造选项
function createOptionForYearSelect(){
	var currentYear = new Date().getFullYear();
	for(var i =currentYear;i>(currentYear-31);i--){
		var html = "<option value='"+i+"'>"+i+"年</option>";
		$("#chooseYearSelect").append(html);
	}
}
/////////////////////////////////
function getMonthDays(month){
	var days = 31;
	switch(month){
	case 2:
		days= 28;break;
	case 4:
	case 6:
	case 9:
	case 11:
		days = 30;break;
	}
	return days;
}

//////////////////////////////////王少波于20130528，加入新增值班人员注册功能/////////////////////
function initMemberRoleAndDepartment(){
	var url = "queryAllMemberRoleAndDepartment.shtml";
	$.post(url,null,function(res){
		$("#addUserDepartment").html("");
		$("#addUserRole").html("");
		//开始填充select
		res = eval("("+res+")");
		var deArray = res.deArray;
		var roArray = res.roArray;
		var htmlDe = "";
		for(var i = 0;i<deArray.length;i++){
			var obj = deArray[i];
			htmlDe = htmlDe+ "<option value='"+obj.deId+"'>"+obj.deName+"</option>";
		}
		var htmlRo = "";
		for(var j = 0;j<roArray.length;j++){
			var obj = roArray[j];
			htmlRo = htmlRo+ "<option value='"+obj.roId+"'>"+obj.roName+"</option>";
		}
		$("#addUserDepartment").append(htmlDe);
		$("#addUserRole").append(htmlRo);
	})
}

